<template>
	<el-container>
		<el-container>
			<el-header>
				<div class="right-panel">
					<div class="right-panel-search">
						<el-input v-model="search.work_task_code" placeholder="搜索单号" clearable></el-input>
						<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
						<el-button type="info" @click="refresh">重置</el-button>
					</div>
				</div>
				<div class="left-panel">
					<!-- <el-button type="danger" :disabled="selection.length == 0" @click="batch_del" v-auth="'spare.deleteAll'">撤回</el-button> -->
                    <el-button type="primary" :disabled="selection.length == 0" @click="end" v-auth="'processPlan.end'">结束</el-button>
				</div>
			</el-header>
			<el-main class="nopadding">
				<scTable @row-dblclick="dblclick" ref="table" :apiObj="apiObj" row-key="id"  @selection-change="selectionChange" stripe remoteSort remoteFilter border>
					<el-table-column fixed="left" type="selection" width="50" reserve-selection></el-table-column>
					<el-table-column label="工序任务单号" prop="work_plan.work_task_code" align="center"></el-table-column>
					<el-table-column label="工序名称" prop="work_plan.work_name" align="center"></el-table-column>
					<el-table-column label="开始时间" prop="start_time" align="center"></el-table-column>
					<el-table-column label="结束时间" prop="end_time" align="center"></el-table-column>
				</scTable>
			</el-main>
		</el-container>
	</el-container>
</template>

<script>
// import saveDialog from "./save.vue";
export default {
	name: 'user',
	components: {
		// saveDialog
	},
	data() {
		return {
			dialog: {
				save: false,
			},
			group: [],
			apiObj: this.$API.production.processtime.list,
			selection: [],
			search: {
				work_task_code: null,
			},
		}
	},
	watch: {

	},
	mounted() {

	},
	methods: {
		/**报工*/
		table_work() {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('add')
			})
		},
		/**查看点击*/
		batch_show() {
			this.$router.push({
				path: '/process/addProject',
			});
		},
		//添加
		add() {
			this.$router.push({
				path: '/process/addProject',
			});
		},
		//编辑
		table_edit() {
			this.$router.push({
				path: '/process/addProject',
			});
		},
		/**双击事件*/
		dblclick(row) {
			this.table_show(row)
		},
		//查看
		table_show(row) {
			let form = row
			form.zhuangtai = 'show'
			this.$router.push({
				path: '/bom/addBom',
				query: form
			});
		},
		//表格内开关
		async changeSwitch(val, row) {
			row.$switch_status = true;
			var res = await this.$API.basicdata.applyList.update_status.post({
				id: row.id,
				system_disable: row.system_disable,
			});
			if (res.code == 1) {
				row.$switch_status = false;
				this.$refs.table.refresh();
				this.$message.success("操作成功");
			} else {
				this.$alert(res.message, "提示", {type: "error"});
			}
		},
		//删除
		async table_del(row, index) {
			var reqData = {id: row.id}
			var res = await this.$API.basicdata.applyList.delete.post(reqData);
			if (res.code == 1) {
				//这里选择刷新整个表格 OR 插入/编辑现有表格数据
				this.$refs.table.tableData.splice(index, 1);
				this.$refs.table.refresh();
				this.$message.success("删除成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSuccess(data, mode) {
			if (mode == 'add') {
				this.$refs.table.refresh()
			} else if (mode == 'edit') {
				this.$refs.table.refresh()
			} else if (mode == 'set') {
				this.$refs.table.refresh()
			}
			this.printArr = ''
		},
		selectionChange(selection) {
			this.selection = selection;
		},
        async table_end_all(data) {
			var reqData = {id: data.ids}
            var res = await this.$API.production.processtime.edit.post(reqData);
			if (res.code == 1) {
				this.$refs.table.refresh()
				this.$message.success("操作成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//批量开始
		async end() {
			var ids = [];
			this.selection.forEach((item) => {
				ids.push(item.id)
			})
			this.$confirm(`确定结束选中的 ${this.selection.length} 项吗？`, '提示', {
				type: 'warning'
			}).then(() => {
				this.table_end_all({ids:ids})
			}).catch(() => {

			})
		},
	}
}
</script>

<style>
.search-input {
	width: auto;
	font-size: 14px;
}

.shopInfo {
	display: flex;
	align-items: center;
}

.img {
	width: 100px;
	height: 100px;
	margin-right: 5px;
}
</style>
